package com.wzh.mq.rabbit;

import com.rabbitmq.client.Channel;
import com.wzh.mq.util.MsgUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.HashMap;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @author WZH
 * @title: Consumer
 * @projectName find_house
 * @description:
 * @date 2022/3/23
 */
@Component
public class UserConsumer {
    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @RabbitListener(queues = "msg2")
    public void take01(String tel, Message message, Channel channel) throws IOException {
        int code = new Random().nextInt(89999)+10000;
        //判断发短信
        MsgUtil.sendMsg(tel, String.valueOf(code));
        redisTemplate.opsForValue().set(tel,String.valueOf(code),3, TimeUnit.MINUTES);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
